<template>
  <div class="order-summary">
    <div class="order-summary__select">
      <div class="legend">
        <span class="item">
          <span class="square" style="background: #FFEA00"></span>
          <span class="title">报修单数</span>
        </span>
        <span class="item">
          <span class="square" style="background: #39E4D6"></span>
          <span class="title">报事单数</span>
        </span>
        <span class="item">
          <span class="square" style="background: #FDA3B6"></span>
          <span class="title">投诉单数</span>
        </span>
        <span class="item">
          <span class="square" style="background: #53ED73"></span>
          <span class="title">表扬单数</span>
        </span>
      </div>
      <div class="order-summary__select-date">
        <el-date-picker
          v-model="dayTime"
          type="month"
          :clearable="false"
          size="mini"
          value-format="yyyy-MM"
          format="yyyy年M月"
          @change="getData">
        </el-date-picker>
      </div>
      <el-checkbox v-model="checked" @change="getData">当天</el-checkbox>
    </div>
    <div class="order-summary__content">
      <ve-histogram ref="chart2" :data="bxData" :judge-width="true" :settings="chartSettings2" :extend="chartExtend2" :width="width" :height="height"></ve-histogram>
      <ve-histogram ref="chart1" :data="bsData"  :judge-width="true" :settings="chartSettings" :extend="chartExtend" :width="width" :height="height"></ve-histogram>
    </div>
     <div class="order-summary__content">
      <ve-histogram ref="chart3" :data="tsData" :settings="chartSettings3" :extend="chartExtend3" :width="width" :height="height"></ve-histogram>
      <ve-histogram ref="chart4" :data="byData" :settings="chartSettings4" :extend="chartExtend4" :width="width" :height="height"></ve-histogram>
    </div>
  </div>
</template>
<script>
import echarts from 'echarts/lib/echarts'
import { Select, Option, Checkbox, DatePicker } from 'element-ui'
import Histogram from 'v-charts/lib/histogram.common'
import { getKhfwDetail } from 'src/api/api'
import { formatDate, formatFontSize } from 'js/utils'
export default {
  components: {
    [Select.name]: Select,
    [Option.name]: Option,
    [Checkbox.name]: Checkbox,
    [Histogram.name]: Histogram,
    [DatePicker.name]: DatePicker,
  },
  data(){
    return {
      width: '25rem',
      height: '16.5rem',
      // height: '263px',
      dayTime: formatDate('yyyy-mm', new Date()),
      checked: false,
      chartSettings: {
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
        legend: {
          show: false
        },
      },
      chartExtend: {
        title: {
          text: '各城市报事单统计图(每50万平方米)',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          right: 0,
        },
        legend: {
          show: false,
        },
        xAxis: {
          axisLabel: {
            color: '#fff',
            // fontSize: 12,
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(63,255,234,0.82)'},
                  {offset: 1, color: 'rgba(0,126,255,0.2)'}
              ]
            )
          },
        }
      },
      chartSettings2: {
        label: {
          show: false
        },
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
        legend: {
          show: false
        },
      },
      chartExtend2: {
        title: {
          text: '各城市报修单统计图(每50万平方米)',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          right: 0,
        },
        legend: {
          show: false,
        },
        xAxis: {
          axisLabel: {
            color: '#fff'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 1, 1,
              [
                  {offset: 0, color: 'rgba(255,234,0,0.82)'},
                  {offset: 1, color: 'rgba(255,157,0,0.2)'}
              ]
            )
          },
        }
      },
      chartSettings3: {
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
        legend: {
          show: false
        },
      },
      chartExtend3: {
        title: {
          text: '各城市投诉单统计图(每50万平方米)',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          right: 0,
        },
        legend: {
          show: false,
        },
        xAxis: {
          axisLabel: {
            color: '#fff'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(255,173,186,0.82)'},
                  {offset: 1, color: 'rgba(232,119,137,0.2)'}
              ]
            )
          },
        }
      },
      chartSettings4: {
        labelMap: {
          'bsNum': '报事单数',
          'jrbxNum': '报修单数',
          'tsNum': '投诉单数',
          'byNum': '表扬单数',
        },
        legend: {
          show: false
        },
      },
      chartExtend4: {
        title: {
          text: '各城市表扬单统计图(每50万平方米)',
          textStyle: {
            color: '#fff',
            fontSize: formatFontSize(0.12),
          },
          right: 0,
        },
        legend: {
          show: false,
        },
        xAxis: {
          axisLabel: {
            color: '#fff'
          },
        },
        yAxis: {
          axisLabel: {
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#fff',
              opacity: 0.1,
            }
          },
          // max: 1000,
          splitNumber: 10,
        },
        grid: {  
          left: '0',  
          right: '0',
          top: '20%',
          bottom: '5%',  
        },
        series: {
          barWidth: formatFontSize(0.2),
          label: { 
            show: true, 
            position: 'top',
            color: '#fff',
            fontSize: formatFontSize(0.1),
          },
          itemStyle: {
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                  {offset: 0, color: 'rgba(83,237,115,0.82)'},
                  {offset: 1, color: 'rgba(6,124,31,0.2)'}
              ]
            )
          },
        }
      },
      bsData: {
        columns: ['cityName', 'bsNum'],
        rows: []
      },
      bxData: {
        columns: ['cityName', 'jrbxNum'],
        rows: []
      },
      tsData: {
        columns: ['cityName', 'tsNum'],
        rows: []
      },
      byData: {
        columns: ['cityName', 'byNum'],
        rows: []
      },
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      let params = {}
      if(this.checked){
        params = {
          dayTime: formatDate('yyyy-mm-dd', new Date())
        }
      } else {
        params = {
          dayTime: this.dayTime
        }
      }
      getKhfwDetail(params).then(res=>{
        this.bsData.rows = res.data
        this.bxData.rows = res.data
        this.tsData.rows = res.data
        this.byData.rows = res.data
      })
    }
  }
}
</script>
<style lang="scss">
.order-summary {
  padding-bottom: 15px;
  &__select {
    text-align: right;
    padding: 5px 40px 5px 0;
    font-size: 14px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    color: #AAECFF;
    .el-select, .el-date-editor {
      .el-input__inner {
        // width: 150px;
        border: 0;
        border-radius: 0;
        background:rgba(11,21,58,1);
        box-shadow:1px 1px 0px 0px rgba(255,255,255,0.25), 0px 2px 4px 0px rgba(0, 0, 0, 1);
        color: #AAECFF;
        font-size: 14px;
      }
      .el-input__icon {
        color: #AAECFF;
        font-size: 14px;
      }
    }
    &-date {
      margin-right: 20px;
      .el-date-editor {
        width: 135px;
      }
    }
    .el-checkbox {
      color: #AAECFF;
    }
    .el-checkbox__input.is-checked+.el-checkbox__label {
      color: #AAECFF;
    }
    .el-checkbox__inner {
      border-radius: 50%;
    }
  }
  .legend {
    display: flex;
    align-items: center;
    padding-right: 50px;
    .item {
      display: flex;
      align-items: center;
      font-size: 12px;
      padding-right: 50px;
    }
    .square {
      height: 10px;
      width: 23px;
      display: block;
      margin-right: 10px;
      // border: 1px solid red;
    }
  }
  &__content {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-around;
    // width: 100%;
  }
}
</style>